package com.guofen.controller.sjq;

import com.guofen.pojo.SjqWaterProductionEquipmentMaintenanceDay;
import com.guofen.pojo.SjqWaterProductionEquipmentMaintenanceMonth;
import com.guofen.pojo.SjqWaterProductionEquipmentMaintenanceWeek;
import com.guofen.service.sjq.SjqWaterProductionEquipmentMaintenanceDayService;
import com.guofen.service.sjq.SjqWaterProductionEquipmentMaintenanceWeekService;
import com.guofen.service.sjq.SjqWaterProductionEquipmentMaintenanceMonthService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


@RequestMapping("/shlj/sjqWaterProductionEquipmentMaintenanceMaintenance")
@Controller
@Api(tags = "SjqWaterProductionEquipmentMaintenanceController", description = "水处理日周月保养")
public class SjqWaterProductionEquipmentMaintenanceController {
    @Autowired
    private SjqWaterProductionEquipmentMaintenanceDayService sjqWaterProductionEquipmentMaintenanceDayService;
    @Autowired
    private SjqWaterProductionEquipmentMaintenanceWeekService sjqWaterProductionEquipmentMaintenanceWeekService;
    @Autowired
    private SjqWaterProductionEquipmentMaintenanceMonthService sjqWaterProductionEquipmentMaintenanceMonthService;

    //日保养
    @ApiOperation("添加记录_日保养_记录人")
    @RequestMapping(value = "/add_day_recorder",method = RequestMethod.POST)
    @ResponseBody
    public Result add_day_recorder(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                                   @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent,
                                   @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                                   @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks,
                                   @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator){
        if (sjqWaterProductionEquipmentMaintenanceDayService.add_operator(equipment_name,maintenanceContent,isNormal,operator,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加记录_日保养_检察人")
    @RequestMapping(value = "/add_day_inspector",method = RequestMethod.POST)
    @ResponseBody
    public Result add_day_inspector(@ApiParam(name="id",value="id",required=true) @RequestParam String id,
                                    @ApiParam(name="Inspector",value="记录人",required=true) @RequestParam String Inspector,
                                    @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks){

        if (sjqWaterProductionEquipmentMaintenanceDayService.add_inspector(id,Inspector,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("获取 当日 日保养记录")
    @RequestMapping(value = "/getlast_day",method = RequestMethod.POST)
    @ResponseBody
    public Result getlast_day(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                              @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent){
        return  ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceDayService.getlast(equipment_name,maintenanceContent));
    }

    @ApiOperation("获取 当日 所有日保养记录")
    @RequestMapping(value = "/getDailyRecords",method = RequestMethod.GET)
    @ResponseBody
    public Result getDailyRecords(){
        return  ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceDayService.getDailyRecords());
    }



    @ApiOperation("检查多个设备日保养是否保养完毕")
    @RequestMapping(value = "/is_day_complete",method = RequestMethod.POST)
    @ResponseBody
    public Result is_day_complete(@ApiParam(name="equipmentsName",value="设备名称",required=true) @RequestParam String equipmentsName,
                                       @ApiParam(name="menstanceNum",value="保养方法数量",required=true) @RequestParam String menstanceNum,
                                       @ApiParam(name="role",value="角色(operator/examiner)",required=true) @RequestParam String role){
        return  ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceDayService.is_last_complete(equipmentsName,menstanceNum,role));
    }

    //周保养
    @ApiOperation("添加记录_周保养_记录人")
    @RequestMapping(value = "/add_week_recorder",method = RequestMethod.POST)
    @ResponseBody
    public Result add_week_recorder(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                                    @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent,
                                    @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                                    @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks,
                                    @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator){
        if (sjqWaterProductionEquipmentMaintenanceWeekService.add_operator(equipment_name,maintenanceContent,isNormal,operator,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加记录_周保养_检察人")
    @RequestMapping(value = "/add_week_inspector",method = RequestMethod.POST)
    @ResponseBody
    public Result add_week_inspector(@ApiParam(name="id",value="id",required=true) @RequestParam String id,
                                     @ApiParam(name="Inspector",value="记录人",required=true) @RequestParam String Inspector,
                                     @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks){

        if (sjqWaterProductionEquipmentMaintenanceWeekService.add_inspector(id,Inspector,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("获取 本周 周保养记录")
    @RequestMapping(value = "/getlast_week",method = RequestMethod.POST)
    @ResponseBody
    public Result getlast_week(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                               @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent){
        return  ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceWeekService.getlast(equipment_name,maintenanceContent));
    }

    @ApiOperation("获取 当周 所有周保养记录")
    @RequestMapping(value = "/getWeekRecords",method = RequestMethod.GET)
    @ResponseBody
    public Result getWeekRecords(){
        return  ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceWeekService.getWeekRecords());
    }


    @ApiOperation("检查多个设备周保养是否保养完毕")
    @RequestMapping(value = "/is_week_complete",method = RequestMethod.POST)
    @ResponseBody
    public Result is_week_complete(@ApiParam(name="equipmentsName",value="设备名称",required=true) @RequestParam String equipmentsName,
                                       @ApiParam(name="menstanceNum",value="保养方法数量",required=true) @RequestParam String menstanceNum,
                                       @ApiParam(name="role",value="角色(operator/examiner)",required=true) @RequestParam String role){
        return  ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceWeekService.is_last_complete(equipmentsName,menstanceNum,role));
    }

    //月保养
    @ApiOperation("添加记录_月保养_记录人")
    @RequestMapping(value = "/add_month_recorder",method = RequestMethod.POST)
    @ResponseBody
    public Result add_month_recorder(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                                     @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent,
                                     @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                                     @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks,
                                     @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator){
        if (sjqWaterProductionEquipmentMaintenanceMonthService.add_operator(equipment_name,maintenanceContent,isNormal,operator,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加记录_月保养_检察人")
    @RequestMapping(value = "/add_month_inspector",method = RequestMethod.POST)
    @ResponseBody
    public Result add_month_inspector(@ApiParam(name="id",value="id",required=true) @RequestParam String id,
                                      @ApiParam(name="Inspector",value="记录人",required=true) @RequestParam String Inspector,
                                      @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks){

        if (sjqWaterProductionEquipmentMaintenanceMonthService.add_inspector(id,Inspector,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("获取 当月 月保养记录")
    @RequestMapping(value = "/getlast_month",method = RequestMethod.POST)
    @ResponseBody
    public Result getlast_month(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                                @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent){
        return  ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceMonthService.getlast(equipment_name,maintenanceContent));
    }


    @ApiOperation("获取 当月 某设备的所有保养记录")
    @RequestMapping(value = "/getMonthRecords",method = RequestMethod.POST)
    @ResponseBody
    public Result getMonthRecords(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name){
        return  ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceMonthService.getMonthRecords(equipment_name));
    }


    @ApiOperation("检查多个设备月保养是否保养完毕")
    @RequestMapping(value = "/is_month_complete",method = RequestMethod.POST)
    @ResponseBody
    public Result is_month_complete(@ApiParam(name="equipmentsName",value="设备名称",required=true) @RequestParam String equipmentsName,
                                   @ApiParam(name="menstanceNum",value="保养方法数量",required=true) @RequestParam String menstanceNum,
                                   @ApiParam(name="role",value="角色(operator/examiner)",required=true) @RequestParam String role){
        return  ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceMonthService.is_last_complete(equipmentsName,menstanceNum,role));
    }

    @ApiOperation("获取至今保存的 日、周、月 保养内容数量")
    @RequestMapping(value = "/getMaintenanceNum", method = RequestMethod.GET)
    @ResponseBody
    public Result getMaintenanceNum() {
        int daily = sjqWaterProductionEquipmentMaintenanceDayService.getInToday();
        int week = sjqWaterProductionEquipmentMaintenanceWeekService.getInThisWeek();
        int month = sjqWaterProductionEquipmentMaintenanceMonthService.getInThisMonth();
        Map<String, Object> map = new HashMap<>();
        map.put("daily", daily);
        map.put("week", week);
        map.put("month", month);
        return ResultGenerator.genSuccessResult(map);
    }

    @ApiOperation("删除日记录")
    @RequestMapping(value = "/day/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result deleteByDay(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceDayService.delete(id));
    }

    @ApiOperation("修改日记录")
    @RequestMapping(value = "/day/update",method = RequestMethod.POST)
    @ResponseBody
    public Result updateByDay(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                         @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent,
                         @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                         @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator,
                         @ApiParam(name="Inspector",value="记录人",required=true) @RequestParam String Inspector,
                         @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks) {
        SjqWaterProductionEquipmentMaintenanceDay record = new SjqWaterProductionEquipmentMaintenanceDay();
        record.setId(id);
        record.setEquipmentName(equipment_name);
        record.setMaintenanceContent(maintenanceContent);
        record.setIsNormal(isNormal);
        record.setOperator(operator);
        record.setInspector(Inspector);
        record.setRemarks(remarks);
        return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceDayService.update(record));
    }

    @ApiOperation("查找日记录")
    @RequestMapping(value = "/day/select",method = RequestMethod.POST)
    @ResponseBody
    public Result selectByDay(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceDayService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceDayService.getByTime(pageSize, currentPage, startTime, endTime));
    }

    @ApiOperation("删除月记录")
    @RequestMapping(value = "/month/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result deleteByMouth(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceMonthService.delete(id));
    }

    @ApiOperation("修改月记录")
    @RequestMapping(value = "/month/update",method = RequestMethod.POST)
    @ResponseBody
    public Result updateByMouth(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                                @ApiParam(name="maintenance_time_plan",value="计划保养日期",required=true) @RequestParam String maintenance_time_plan,
                                @ApiParam(name="maintenance_time_implement",value="实际保养日期",required=true) @RequestParam String maintenance_time_implement,
                                @ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                                @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent,
                                @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                                @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks,
                                @ApiParam(name="Inspector",value="记录人",required=true) @RequestParam String Inspector,
                                @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator) {
        SjqWaterProductionEquipmentMaintenanceMonth record = new SjqWaterProductionEquipmentMaintenanceMonth();
        record.setId(id);
        record.setMaintenanceTimePlan(maintenance_time_plan);
        record.setMaintenanceTimeImplement(maintenance_time_implement);
        record.setEquipmentName(equipment_name);
        record.setMaintenanceContent(maintenanceContent);
        record.setIsNormal(isNormal);
        record.setInspector(Inspector);
        record.setOperator(operator);
        record.setRemarks(remarks);
        return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceMonthService.update(record));
    }

    @ApiOperation("查找月记录")
    @RequestMapping(value = "/month/select",method = RequestMethod.POST)
    @ResponseBody
    public Result selectByMouth(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceMonthService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceMonthService.getByTime(pageSize, currentPage, startTime, endTime));
    }

    @ApiOperation("删除周记录")
    @RequestMapping(value = "/delete_week",method = RequestMethod.POST)
    @ResponseBody
    public Result deleteByWeek(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceWeekService.delete(id));
    }

    @ApiOperation("修改周记录")
    @RequestMapping(value = "/update_week",method = RequestMethod.POST)
    @ResponseBody
    public Result updateByWeek(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                               @ApiParam(name="maintenance_time_plan",value="计划保养日期",required=true) @RequestParam String maintenance_time_plan,
                               @ApiParam(name="maintenance_time_implement",value="实际保养日期",required=true) @RequestParam String maintenance_time_implement,
                               @ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                               @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent,
                               @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                               @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks,
                               @ApiParam(name="Inspector",value="记录人",required=true) @RequestParam String Inspector,
                               @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator) {
        SjqWaterProductionEquipmentMaintenanceWeek record = new SjqWaterProductionEquipmentMaintenanceWeek();
        record.setId(id);
        record.setMaintenanceTimePlan(maintenance_time_plan);
        record.setMaintenanceTimeImplement(maintenance_time_implement);
        record.setEquipmentName(equipment_name);
        record.setMaintenanceContent(maintenanceContent);
        record.setIsNormal(isNormal);
        record.setInspector(Inspector);
        record.setOperator(operator);
        record.setRemarks(remarks);
        return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceWeekService.update(record));
    }

    @ApiOperation("查找周记录")
    @RequestMapping(value = "/select_week",method = RequestMethod.POST)
    @ResponseBody
    public Result selectByWeek(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceWeekService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqWaterProductionEquipmentMaintenanceWeekService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
